const User = require('../model/user');
const tools = require('../utils/tools');
let jwtUils = require('../utils/jwtUtils');




const getUserDataByName=async (username, resp)=>{
    let data = await User.getUserDataByName(username);
    resp.send({data,code:200})
}

const changeUserPwd=async  (req, resp)=>{
    let data = await User.changeUserPwd(req.body.password, req.body.id);
    resp.send({data,code:200})
}
/**
 * 注册
 * @param req
 * @param resp
 * @returns {Promise<void>}
 */
const insertUser=async  (req, resp)=>{
    console.log(req.body.user)
    let { username,password, Emil, id, head}=req.body.user
    let data = await User.insertUser(username,password, Emil, id, head);
    resp.send({data,code:200})
}

/**
 * 插入todos
 * @param req
 * @param resp
 * @returns {Promise<void>}
 */
const insertTodo=async  (req, resp)=>{
    // console.log(req.body.user)
    // let { username,password, Emil, id, head}=req.body.user
    // let data = await User.insertUser(username,password, Emil, id, head);
    // resp.send({data,code:200})
let {id,uid,collect ,content,deadline,start,updatetime}=req.body
    updatetime=JSON.stringify(updatetime)
    let data=await  User.insertTodo(id,uid,collect ,content,deadline,start,updatetime)
    resp.send({data,code:200})
}

module.exports = {
    getUserDataByName,
    changeUserPwd,
    insertUser,
    insertTodo
};
